<form id="storeform">
	<div class="main">
		<div class="detail" id="frame_store_box">

			<#list depotList as depot>
			<h1>${depot.depotname}</h1>
			<hr />
			<table class="layui-table" lay-even lay-skin="nob">
				<thead>
					<th>货号</th> <#list specNameList as specName>
					<th>${specName}</th> </#list>
					<th>库存</th>
					<th>进货量</th>
				</thead>


				<#assign productList=depot.productList />
				<tbody>
					<#if productList?exists > <#list productList as product>
					<tr>
						<td>${product.sn}</td> <#list product.specList as spec> <#if
						spec.spec_type==1>
						<td>
							<div class="select-spec-unselect spec_selected">
								<center>
									<img height="20" width="20" src="${spec.spec_image}"
										alt="${spec.spec_value}" title="${spec.spec_value}">
								</center>
							</div></td> </#if> <#if spec.spec_type==0>
						<td>
							<div class="select-spec-unselect spec_selected">
								<span>${spec.spec_value}</span>
							</div></td> </#if> </#list>

						<td>${product.store}</td>
						<td>
							<input type="hidden" name="id"  value="${product.storeid}" /> 
							<input type="hidden" name="productid"  value="${product.product_id}" />
<!-- 						 <input type="input" disabled="true" class="input_text" name="storeNum" style="width: 60px;" store="${product.store}" value="0" autocomplete="off" />  
 -->					 
							<input max="999999" min="0" style="width: 80px" name="storeNum" size="6" autocomplete="off"  lay-verify="required" class="layui-input" type="number" value="${(product.store)!'0'}">
							<input type="hidden" name="depotid"  value="${depot.depotid}" /> 
							<!--  <input type="button" class="button" value="进货" class="stockbtn" id="stockbtn" />  -->
						</td>
					</tr>
					</#list> </#if>
				</tbody>

			</table>
			</#list>
		</div>
	</div>
	<div class="layui-layer-btn" style="padding:8px 12px;z-index:1000;position:absolute;bottom:auto;"> 
		<a class="layui-layer-btn0" type="submit" lay-submit="" lay-filter="save-stock">保存</a>
		<a class="layui-layer-btn1">取消</a>
	</div>
</form>
<script type="text/javascript">
	var index = parent.layer.getFrameIndex(window.name);
	
	//绑定事件
	layui.use(['form', 'layedit', 'laydate'], function(){
	    var form = layui.form()
	        ,layer = layui.layer
	        ,layedit = layui.layedit
	        ,laydate = layui.laydate;
	    
	    //取消
	    $(".layui-layer-btn1").click(function(){
	    	parent.layer.close(index);
	    });
	    
	    //提交
		form.on('submit(save-stock)', function(data){
			
			//数字格式的验证和非空验证
			var storeNum = $("input[name='storeNum']");
			var num =/^(0|[1-9][0-9]*)$/;
			for(var i = 0;i<storeNum.length;i++){
				var name = $(storeNum[i]).attr("value");
				if(name==""){
				parent.$.Loading.error("库存不能为空");
				return;	
				}
				if(!num.test(name)){
				parent.$.Loading.error("整型数字格式不正确");
				return;
				}
			}
			
	    	var options = {
	   			url:ctx+"/shop/admin/goods-store/save-stock.do",
	   			type:"post",
	   			dataType:"json",
	   			success:function(data){
	   				if(data.result==1){	
	   					$.Loading.success(data.message);
	   					parent.layer.close(index); //再执行关闭        
	   					parent.table.ajax.url(ctx+"/shop/admin/goods-store/list-goods-store-json.do").load();
	   				}else{
	   					$.Loading.error(data.message);
	   				}
	   			}
	   		};
	   		$("#storeform").ajaxSubmit(options);
	       return false;
	    });

	});
</script>
